<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>房间管理</title>
		<link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css" />
		<link rel="stylesheet" type="text/css" href="${s.base}/lib/dtree/dtree.css"/>
		<link rel="stylesheet" type="text/css" href="${s.base}/lib/dtree/font/iconfont.css"/>
	</head>
	<style type="text/css">
		body,html{width:100%;height:100%;}
	</style>
	<body>
		<div class="maintree">
			<div class="shoubtn switchbtn"><i class="iconfont">&#xe628;</i><i class="iconfont hide">&#xe939;</i></div>
			<div class="maintree-left">
				<div class="mainltree-left-tit">
					场所列表
				</div>
				<ul id="demoTree" class="dtree" data-id="0">
				</ul>
			</div>
			<div class="maintree-right">
				<div class="wrap-container clearfix">
					<div class="column-content-detail padt10" >
						<!--右侧内容部分开始-->
						<form class="layui-form">
							<div class="search-cont clearfix" id="tool">
								<div class="operation-btn-cont">
									<div class="operright cyt-retract-close hideMenu"> 收起筛选<i class="iconfont">&#xe658;</i></div>
									<div class="operright cyt-retract-open showMenu" style="display: none;"> 展开筛选<i class="iconfont">&#xe936;</i></div>
									<!--button开始-->
									<button class="layui-btn layui-btn-normal layui-btn-mid" type="button" id="addBtn"><i class="iconfont marr5">&#xe65e;</i>添加</button>
									<button class="layui-btn layui-btn-normal layui-btn-mid" type="button" id="deleteBtn"><i class="iconfont marr5">&#xe6a3;</i>删除</button>
									<button class="layui-btn layui-btn-normal layui-btn-mid" type="button" id="selectFile"><i class="iconfont marr5">&#xe612;</i>房间导入</button>
									<button class="layui-btn layui-btn-normal layui-btn-mid" type="button" id="exportBtn"><i class="iconfont marr5">&#xe612;</i>模板下载</button>
									<!--button结束-->
									<div class="triangle-bottom"></div>
									<div class="triangle-top"></div>
								</div>
								<div class="search-details">
									<div class="layui-form-item marb5">
										<!--search开始-->
										<div class="layui-inline">
											<label class="layui-form-label">房间号：</label>
											<div class="layui-input-inline">
												<input type="text" name="roomNum" placeholder="请输入房间号" autocomplete="off" class="layui-input">
											</div>
										</div>
										<div class="layui-inline">
											<label class="layui-form-label">房间名：</label>
											<div class="layui-input-inline">
												<input type="text" name="roomName" placeholder="请输入房间名" autocomplete="off" class="layui-input">
											</div>
										</div>
										<div class="layui-inline">
											<label class="layui-form-label">房间类型：</label>
											<div class="layui-input-inline">
												<select name="roomType" id="roomType"></select>
											</div>
										</div>
										<!--search结束-->
										<div class="layui-inline marl8">
											<button class="layui-btn layui-btn-normal" type="button" lay-submit="" lay-filter="seacherBtn">搜索</button>
											<button class="layui-btn layui-btn-normal" type="reset">重置</button>
										</div>
									</div>
								</div>
							</div>
						</form>
						<div class="layui-form" id="table-list">
							<table id="entityList" lay-filter="entityList" class="cy-list-table"></table>
						</div>
						<!--右侧内容部分结束-->
					</div>
				</div>
			</div>
		</div>

		<!--操作-->
		<script type="text/html" id="entityBar">
			<a class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-green" lay-event="edit">编辑</a>
			<button type="button" class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-red" lay-event="delete">删除</button>
		</script>
	<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
		<script>
            //Demo
            var applyId='${applyId}';
            var tableIns = null;
            var parentId='';
            layui.use(['form', 'dialog','jquery','dtreeUtil','dtree','page','table','upload'], function(){
                var form = layui.form
					,$ = layui.jquery
                    ,dialog = layui.dialog
					, dtree = layui.dtree,
					page=layui.page,
					table=layui.table,
					upload=layui.upload
					,dtreeUtil = layui.dtreeUtil;
                $("#demoTree").html("");
                page.initDict('roomType', function (dictData) {
                    page.showDict($("#roomType"), page.aceeptDictContentList(dictData, 'roomType'), "全部");
                });
                var renderTable =function () {
                    page.initDict('roomType', function (dictData) {
                        var url= "/wb/wxwbroom/page?applyId="+applyId+"&bulidId="+parentId;
                        var cols = [
                            {type: 'checkbox', fixed: 'left'},
                            {field: 'roomNum', title: '房间号', align: 'center'},
                            {field: 'roomName', title: '房间名称', align: 'center'},
                            {field: 'floorNum', title: '房间楼层', align: 'center'},
                            {field: 'roomType', title: '房间用途', align: 'center',templet: function (d) {
                                return page.aceeptDictContentName(dictData, 'roomType', d.roomType);
                            }},
                            {field: 'sort', title: '排序', align: 'center',width:100},
                            {title: '操作', width: 220, templet: '#entityBar', align: "center"}
                        ];
                        tableIns = page.initDate(cols, url);
                    });
                }
                dtreeUtil.pageDtree("#demoTree","/wb/wxwbbulid/dTreeListRoom?applyId="+applyId,false,function (data,obj) {
                });
                dtreeUtil.dTreeClick("demoTree",function (param) {
                    parentId=param.nodeId;
                    //获取分页数
                    renderTable();
                });
                renderTable();
                //监听新增事件
                $("#addBtn").bind("click",function () {
                    dialog.popUpPage( "房间添加","/wb/wxwbroom/getAdd?applyId="+applyId+"&bulidId="+parentId,"800px","600px", function (layer, index) {
                        var body = layer.getChildFrame('body', index);
                        body.find("#save").bind("click", function () {
                            parent.layer.closeAll();
                            renderTable();
                        });
                        body.find("#cancel").bind("click", function () {
                            parent.layer.closeAll();
                        });
                    });
                });
                //监听删除按钮事件
                $('#deleteBtn').bind('click', function () {
                    var data = table.checkStatus('entityList').data;
                    if (data.length === 0) {
                        dialog.msg("请先选择对象");
                        return false;
                    } else {
                        var ids = [];
                        for (var i = 0; i < data.length; i++) {
                            ids.push(data[i].id)
                        }
                        page.delete('/wb/wxwbroom/remove', {"id": ids.join(","), "_method": "DELETE"}, "您确定要删除吗？", function () {
                            table.reload("entityList", {
                                where: {}
                            });
                        });
                    }
                });
                //监听模板下载
                $("#exportBtn").on("click",function () {
                    window.location.href = "/work/wxwbroom/export?applyId="+applyId;
                });

                //监听行工具事件
                table.on('tool(entityList)', function (obj) {
                    var layEvent = obj.event,
                        data = obj.data;
                    if (layEvent === 'edit') {
                        dialog.popUpPage( "房间编辑","/wb/wxwbroom/getAdd?id="+data.id+"&applyId="+applyId,"800px","600px", function (layer, index) {
                            var body = layer.getChildFrame('body', index);
                            body.find("#save").bind("click", function () {
                                parent.layer.closeAll();
                                renderTable();
                            });
                            body.find("#cancel").bind("click", function () {
                                parent.layer.closeAll();
                            });
                        });
                    }
                    if (layEvent === 'delete') {
                        page.delete('/wb/wxwbroom/remove', {"id": data.id, "_method": "DELETE"}, "确定删除吗？", function () {
                            tableIns.reload();
                        });
                    }
                });

                upload.render({
                    elem: '#selectFile'
                    ,url: '/work/wxwbroom/importExcel'
                    , accept: 'file'
                    , data: {applyId:applyId}
                    , multiple: true
                    , auto: true
                    ,before:function(obj){
                        layer.load();
                    }
                    ,done:function(res){
                        curr=1;
                        layer.closeAll('loading');
                        if (res.code === 0) {
                            dialog.msg(res.msg);
                            renderTable();
                        } else {
                            dialog.msg(res.msg);
                        }
                    }
                });
            });
		</script>
	</body>
</html>